package com.kuang.sync.pfsidown;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kuang.mapper.AstControllerPoweronMapper;
import com.kuang.mapper.pfsi.AstPfsiDeviceBranchMapper;
import com.kuang.mapper.pfsi.AstPfsiDeviceOpenMapper;
import com.kuang.mapper.pfsi.AstPfsiDeviceStateMsgMapper;
import com.kuang.pojo.AstControllerPoweron;
import com.kuang.pojo.pfsi.AstPfsiDeviceBranch;
import com.kuang.pojo.pfsi.AstPfsiDeviceOpen;
import com.kuang.pojo.pfsi.AstPfsiDeviceStateMsg;
import com.kuang.sync.managedown.ManageDownServiceImpl;
import com.kuang.utils.ControllerLogUtils;
import com.kuang.utils.MQTTConnect;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class PfsiDownServiceImpl implements PfsiDownService{

    @Value("${mqtt.sfurl}")
    String url;

    @Resource
    MQTTConnect mqttConnect;
    @Resource
    AstPfsiDeviceOpenMapper astPfsiDeviceOpenMapper;
    @Resource
    AstPfsiDeviceBranchMapper astPfsiDeviceBranchMapper;
    @Resource
    AstPfsiDeviceStateMsgMapper astPfsiDeviceStateMsgMapper;

    Logger logger = Logger.getLogger(ManageDownServiceImpl.class);

    @Override
    public String postPfsiDeviceRegisterSrv(String id, JSONObject preant) throws MqttException {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/sfRegist";

        preant.put("device_code", id);
        String requestBody = JSON.toJSONString(preant);
        String responseBody="";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();
            // 对响应进行处理
            // 比如转成map
            JSONObject jsonObject = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON
            logger.info("信息:"+JSON.toJSONString(responseBody));

            String success = jsonObject.getString("success");
            String msg = jsonObject.getString("msg");
            if (StringUtils.equals("true",success)){
                JSONObject data = jsonObject.getJSONObject("data");
                boolean pub = mqttConnect.pub("/pfsi/down/"+id, JSON.toJSONString(data));//发布主题
                int i = ControllerLogUtils.setMsgLog("post", address,
                        "水肥一体机-管理机注册","成功", JSON.toJSONString(preant), JSON.toJSONString(responseBody));

            }else {
                int i = ControllerLogUtils.setErrorMsgLog("post", address,
                        "水肥一体机-管理机注册",msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
                logger.info("错误信息:"+msg);
                //发送返回讯息
                JSONObject toJson = new JSONObject();
                JSONObject data = new JSONObject();
                toJson.put("cmd", MapUtils.getIntValue(preant,"cmd"));
                toJson.put("ver",MapUtils.getString(preant,"ver"));
                data.put("state","0");
                toJson.put("data",data);
                boolean pub = mqttConnect.pub("/pfsi/down/"+id, JSON.toJSONString(toJson));//发布主题
            }

        }catch (Exception e){
            int i = ControllerLogUtils.setErrorMsgLog("post", address,
                    "水肥一体机-管理机注册",e.getMessage(), JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            logger.info("错误信息:"+e.getMessage());

            //发送返回讯息
            JSONObject toJson = new JSONObject();
            JSONObject data = new JSONObject();
            toJson.put("cmd", MapUtils.getIntValue(preant,"cmd"));
            toJson.put("ver",MapUtils.getString(preant,"ver"));
            data.put("state","0");
            toJson.put("data",data);
            boolean pub = mqttConnect.pub("/pfsi/down/"+id, JSON.toJSONString(toJson));//发布主题

            return  null;
        }

        return null;
    }

    @Override
    public String postBranchMixingPump(String id, JSONObject preant) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/zljbbSwitchResp";

        preant.put("device_code", id);
        String requestBody = JSON.toJSONString(preant);
        String responseBody="";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();
            // 对响应进行处理
            // 比如转成map
            JSONObject jsonObject = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON
            String success = MapUtils.getString(jsonObject, "success", "");
            String msg = MapUtils.getString(jsonObject, "msg", "");
            if (StringUtils.equals(success,"true")){
                int i = ControllerLogUtils.setMsgLog("post", address,
                        "返回-远程控制支路搅拌泵开关",msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }else {
                int i = ControllerLogUtils.setErrorMsgLog("post", address,
                        "返回-远程控制支路搅拌泵开关",msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }
        }catch (Exception e){
            int i = ControllerLogUtils.setErrorMsgLog("post", address,
                    "返回-远程控制支路搅拌泵开关",e.getMessage(), JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            logger.info("错误信息:"+e.getMessage());

            return  null;
        }

        logger.info("信息:"+JSON.toJSONString(responseBody));

        return null;
    }

    @Override
    public String postBranchInput(String id, JSONObject preant) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/branchInputResp";
        String name = "返回-远程控制支路进水口开关";

        preant.put("device_code", id);
        String requestBody = JSON.toJSONString(preant);
        String responseBody="";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();

            // 对响应进行处理,比如转成map
            JSONObject jsonObject = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON
            String success = MapUtils.getString(jsonObject, "success", "");
            String msg = MapUtils.getString(jsonObject, "msg", "");

            if (StringUtils.equals(success,"true")){
                int i = ControllerLogUtils.setMsgLog("post", address,
                        name,msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }else {
                int i = ControllerLogUtils.setErrorMsgLog("post", address,
                        name,msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }

        }catch (Exception e){
            int i = ControllerLogUtils.setErrorMsgLog("post", address,
                    name,e.getMessage(), JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            logger.info("错误信息:"+e.getMessage());
            return  null;
        }

        logger.info("信息:"+JSON.toJSONString(responseBody));

        return null;
    }

    @Override
    public String postBranchOutput(String id, JSONObject preant) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/branchOutputResp";
        String name = "返回-远程控制支路出水口开关";

        preant.put("device_code", id);
        String requestBody = JSON.toJSONString(preant);
        String responseBody="";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();

            // 对响应进行处理,比如转成map
            JSONObject jsonObject = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON
            String success = MapUtils.getString(jsonObject, "success", "");
            String msg = MapUtils.getString(jsonObject, "msg", "");

            if (StringUtils.equals(success,"true")){
                int i = ControllerLogUtils.setMsgLog("post", address,
                        name,msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }else {
                int i = ControllerLogUtils.setErrorMsgLog("post", address,
                        name,msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }

        }catch (Exception e){
            int i = ControllerLogUtils.setErrorMsgLog("post", address,
                    name,e.getMessage(), JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            logger.info("错误信息:"+e.getMessage());
            return  null;
        }

        logger.info("信息:"+JSON.toJSONString(responseBody));

        return null;
    }

    @Override
    public String postWaterOrFertiPump(String id, JSONObject preant) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/waterOrFertiPumpResp";
        String name = "返回-远程控制水泵或者肥泵";

        JSONObject data = preant.getJSONObject("data");

        JSONObject toJson = new JSONObject();
        JSONObject toData = new JSONObject();
        toJson.put("device_code", id);
        toJson.put("cmd", MapUtils.getIntValue(preant,"cmd"));
        toJson.put("ver", MapUtils.getString(preant,"ver",""));

        String water_pump = MapUtils.getString(data, "water_pump", "");
        String ferti_pump = MapUtils.getString(data, "ferti_pump", "");

        if (StringUtils.isNotBlank(water_pump)){
            toData.put("type","water_pump");
            toData.put("pump",water_pump);
        }else if (StringUtils.isNotBlank(ferti_pump)){
            toData.put("type","ferti_pump");
            toData.put("pump",ferti_pump);
        }

        toJson.put("data",toData);

        String requestBody = JSON.toJSONString(toJson);
        String responseBody="";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();

            // 对响应进行处理,比如转成map
            JSONObject jsonObject = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON
            String success = MapUtils.getString(jsonObject, "success", "");
            String msg = MapUtils.getString(jsonObject, "msg", "");

            if (StringUtils.equals(success,"true")){
                int i = ControllerLogUtils.setMsgLog("post", address,
                        name,msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }else {
                int i = ControllerLogUtils.setErrorMsgLog("post", address,
                        name,msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }

        }catch (Exception e){
            int i = ControllerLogUtils.setErrorMsgLog("post", address,
                    name,e.getMessage(), JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            logger.info("错误信息:"+e.getMessage());
            return  null;
        }

        logger.info("信息:"+JSON.toJSONString(responseBody));

        return null;
    }

    @Override
    public String postPfsiDeviceOpen(AstPfsiDeviceOpen astPfsiDeviceOpen) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/pfsiPoweron";
        String controller_name = "iot推送水肥一体机-设备端开机给平台";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ObjectMapper objectMapper = new ObjectMapper();
        JSONObject data;
        String create_time = "";

        create_time = simpleDateFormat.format(astPfsiDeviceOpen.getCreate_time());
        data = objectMapper.convertValue(astPfsiDeviceOpen, JSONObject.class);
        data.put("create_time", create_time);

        String requestBody = JSON.toJSONString(data);
        String responseBody = "";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();
            // 对响应进行处理
            // 比如转成map
            JSONObject jsonObject = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON
            logger.info("信息:" + JSON.toJSONString(responseBody));

            String success = jsonObject.getString("success");
            String msg = jsonObject.getString("msg");

            if (StringUtils.equals("true", success)) {
                int i = ControllerLogUtils.setMsgLog("post", address,
                        controller_name, msg, requestBody, responseBody);
                astPfsiDeviceOpen.setSuccess("true");
                int update = astPfsiDeviceOpenMapper.update(astPfsiDeviceOpen);
            } else {
                logger.info("错误信息:" + msg);
                int i = ControllerLogUtils.setErrorMsgLog("post", address,
                        controller_name, msg, requestBody, responseBody);
                astPfsiDeviceOpen.setSuccess("flase");
                int update = astPfsiDeviceOpenMapper.update(astPfsiDeviceOpen);
            }

        } catch (Exception e) {
            logger.info("错误信息:" + e.getMessage());
            int i = ControllerLogUtils.setErrorMsgLog("post", address,
                    controller_name, e.getMessage(), requestBody, responseBody);
            astPfsiDeviceOpen.setSuccess("flase");
            int update = astPfsiDeviceOpenMapper.update(astPfsiDeviceOpen);

            return null;
        }

        return null;
    }

    @Override
    public String postPfsiDeviceStateMsg(AstPfsiDeviceStateMsg astPfsiDeviceStateMsg) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/deviceStateMsg";
        String controller_name = "iot推送水肥一体机-设备状态信息给平台";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ObjectMapper objectMapper = new ObjectMapper();
        JSONObject data;
        String create_time = "";

        create_time = simpleDateFormat.format(astPfsiDeviceStateMsg.getCreate_time());
        data = objectMapper.convertValue(astPfsiDeviceStateMsg, JSONObject.class);
        data.put("create_time", create_time);

        String requestBody = JSON.toJSONString(data);
        String responseBody = "";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();
            // 对响应进行处理
            // 比如转成map
            JSONObject jsonObject = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON
            logger.info("信息:" + JSON.toJSONString(responseBody));

            String success = jsonObject.getString("success");
            String msg = jsonObject.getString("msg");

            if (StringUtils.equals("true", success)) {
                int i = ControllerLogUtils.setMsgLog("post", address,
                        controller_name, msg, requestBody, responseBody);
                astPfsiDeviceStateMsg.setSuccess("true");
                int update = astPfsiDeviceStateMsgMapper.update(astPfsiDeviceStateMsg);
            } else {
                logger.info("错误信息:" + msg);
                int i = ControllerLogUtils.setErrorMsgLog("post", address,
                        controller_name, msg, requestBody, responseBody);
                astPfsiDeviceStateMsg.setSuccess("flase");
                int update = astPfsiDeviceStateMsgMapper.update(astPfsiDeviceStateMsg);
            }

        } catch (Exception e) {
            logger.info("错误信息:" + e.getMessage());
            int i = ControllerLogUtils.setErrorMsgLog("post", address,
                    controller_name, e.getMessage(), requestBody, responseBody);
            astPfsiDeviceStateMsg.setSuccess("flase");
            int update = astPfsiDeviceStateMsgMapper.update(astPfsiDeviceStateMsg);

            return null;
        }

        return null;
    }

    @Override
    public String postPfsiDeviceBranch(AstPfsiDeviceBranch astPfsiDeviceBranch) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/deviceBranch";
        String controller_name = "iot推送水肥一体机-肥通支路信息给平台";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ObjectMapper objectMapper = new ObjectMapper();
        JSONObject data;
        String create_time = "";

        create_time = simpleDateFormat.format(astPfsiDeviceBranch.getCreate_time());
        data = objectMapper.convertValue(astPfsiDeviceBranch, JSONObject.class);
        data.put("create_time", create_time);

        String requestBody = JSON.toJSONString(data);
        String responseBody = "";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();
            // 对响应进行处理
            // 比如转成map
            JSONObject jsonObject = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON
            logger.info("信息:" + JSON.toJSONString(responseBody));

            String success = jsonObject.getString("success");
            String msg = jsonObject.getString("msg");

            if (StringUtils.equals("true", success)) {
                int i = ControllerLogUtils.setMsgLog("post", address,
                        controller_name, msg, requestBody, responseBody);
                astPfsiDeviceBranch.setSuccess("true");
                int update = astPfsiDeviceBranchMapper.update(astPfsiDeviceBranch);
            } else {
                logger.info("错误信息:" + msg);
                int i = ControllerLogUtils.setErrorMsgLog("post", address,
                        controller_name, msg, requestBody, responseBody);
                astPfsiDeviceBranch.setSuccess("flase");
                int update = astPfsiDeviceBranchMapper.update(astPfsiDeviceBranch);
            }

        } catch (Exception e) {
            logger.info("错误信息:" + e.getMessage());
            int i = ControllerLogUtils.setErrorMsgLog("post", address,
                    controller_name, e.getMessage(), requestBody, responseBody);
            astPfsiDeviceBranch.setSuccess("flase");
            int update = astPfsiDeviceBranchMapper.update(astPfsiDeviceBranch);

            return null;
        }

        return null;
    }

    @Override
    public String postRemotePfsiValveResp(String id, JSONObject preant) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/remotePfsiValveResp";
        String name = "返回-水肥-远程控制阀门（iot-平台)\n";

        String requestBody = JSON.toJSONString(preant);
        String responseBody="";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();

            // 对响应进行处理,比如转成map
            JSONObject jsonObject = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON
            String success = MapUtils.getString(jsonObject, "success", "");
            String msg = MapUtils.getString(jsonObject, "msg", "");

            if (StringUtils.equals(success,"true")){
                int i = ControllerLogUtils.setMsgLog("post", address,
                        name,msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }else {
                int i = ControllerLogUtils.setErrorMsgLog("post", address,
                        name,msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            }

        }catch (Exception e){
            int i = ControllerLogUtils.setErrorMsgLog("post", address,
                    name,e.getMessage(), JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            logger.info("错误信息:"+e.getMessage());
            return  null;
        }

        logger.info("信息:"+JSON.toJSONString(responseBody));

        return null;
    }

    @Override
    public String posUpdatePfsiValveStatus(String id, JSONObject preant) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String address = "/pfsi/down/updatePfsiValveStatus\n";

        //处理数据 begin
        JSONObject data = preant.getJSONObject("data");
        int num = 1, son;
        String decoder, twoS;
        List<Map> list = new ArrayList();
        Map param;
        char[] twoC;

        for (int j = 1; j <= 8; j++) {
            decoder = MapUtils.getString(data, "decoder" + j, "0");
            //16进制转10进制
            son = Integer.parseInt(String.valueOf(decoder), 16);
            //10进制转2进制
            twoS = Integer.toBinaryString(son);
            //字符串倒序
            twoS = ControllerLogUtils.reverseString(twoS);
            //循环便利字符串
            for (int i = 0; i < 32; i++) {

                param = new LinkedHashMap();
                twoC=twoS.toCharArray();
                if (i + 1 <= twoC.length) {

                    param.put("decoder_adr", num);

                    if (StringUtils.equals("1", String.valueOf(twoC[i]))) {
                        param.put("state", "on");
                    } else {
                        param.put("state", "off");
                    }//if-else

                }else {
                    param.put("decoder_adr", num);
                    param.put("state", "off");
                }

                list.add(param);
                num++;

            }//for

        }//for
        preant.put("data",list);
        //处理数据 end

        String requestBody = JSON.toJSONString(preant);
        String responseBody = "";

        try {
            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.postForEntity(url + address, requestEntity, String.class);
            responseBody = response.getBody();
            // 对响应进行处理
            // 比如转成map
            Map<String, Object> map = JSONObject.parseObject(responseBody);
            //在这个示例中，我们使用postForEntity()方法发送POST请求，并在请求体中传递了JSON

            String success = MapUtils.getString(map, "success", "");
            String msg = MapUtils.getString(map, "msg", "");
            if (StringUtils.equals("false", success)) {
                //int i = ControllerLogUtils.setErrorMsgLog("post", address,"获取设备端信息", msg, JSON.toJSONString(preant), JSON.toJSONString(responseBody));
                logger.info("错误信息:" + msg);
                return null;
            }

        } catch (Exception e) {
            //int i = ControllerLogUtils.setErrorMsgLog("post", address,"获取设备端信息", e.getMessage(), JSON.toJSONString(preant), JSON.toJSONString(responseBody));
            logger.info("错误信息:" + e.getMessage());
            return null;
        }

        //int i = ControllerLogUtils.setMsgLog("post", address,"获取设备端信息", "成功", JSON.toJSONString(preant), JSON.toJSONString(responseBody));
        logger.info("错误信息:" + JSON.toJSONString(responseBody));

        return null;
    }


}
